﻿(function () {
    var getJson = function(serviceUrl, headers) {
        return WinJS.xhr({
            "type": "GET",
            "url": serviceUrl,
            "responseType": "application/json",
            "headers": headers
        });
    }

    var postJson = function(serviceUrl, data, headers) {
        return WinJS.xhr({
            "type": "POST",
            "url": serviceUrl,
            "data": JSON.stringify(data),
            "responseType": "application/json",
            "headers": headers
        });
    }

    var putJson = function (serviceUrl, data, headers) {
        return WinJS.xhr({
            "type": "PUT",
            "url": serviceUrl,
            "data": JSON.stringify(data),
            "responseType": "application/json",
            "headers": headers
        });
    }

    WinJS.Namespace.define("HttpRequester", {
        getJSON: function (serviceUrl, headers) {
            return getJson(serviceUrl, headers);
        },
        postJSON: function(serviceUrl, data, headers) {
            return postJson(serviceUrl, data, headers);
        },
        putJson: function (serviceUrl, data, headers) {
            return putJson(serviceUrl, data, headers);
        }
    });
}());